<?

require_once SITE_ROOT_PATH."/_lib/classes/class.holiday_top_deals.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.destinations.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.airports.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.lurls.php";


class offers_2_rss {





// Create RSS doc
function get_rss(){



$rss_head = "<?xml version=\"1.0\"?>
<rss version=\"2.0\">
  <channel>
    <title>Late Deal Holidays</title>
    <link>http://www.latedeals.ie</link>
    <description>Late Deal Holidays from Ireland to the top mediterranean holiday resorts</description>
    <language>en</language>
    <pubDate>".date('D, d M Y g:i:s O')."</pubDate>
	<image>http://www.latedeals.ie/images/latedeals_logo.png</image>
	";

$rss_item = "<item>
      <title>%title%</title>
      <link>%link%</link>
	  <pubDate>%pubDate% GMT</pubDate>
    </item>
	";

$rss_foot = "  </channel>
</rss>";




	$holiday_top_deals = new holiday_top_deals();

	
	$params['limit'] = '10';
	$holiday_values = $holiday_top_deals->get_top_deals($params);
	unset($params);

	
	if(!empty($holiday_values)){
	
		$destinations = new destinations();
		$airports = new airports();
		$lurls = new lurls();

	foreach($holiday_values as $values_top_deals){
	
		// Get destination using airport code and name synonyms as paramaters
		$params['airport_code'] = $values_top_deals['destination_airport'];
		$params['type_id'] = '1';
		$params['position'] = 'bottom';
		$destination_values = $destinations->destination_lookup($params);
		unset($params);
		
		// Get departure airport
		$params['airport_code'] = $values_top_deals['departure_airport'];
		$item_departure_airport = $airports->get_airport($params);
		unset($params);
		
		$url_string = "http://www.latedeals.ie".$lurls->holiday_list_lurl($values_top_deals);
		
		$data_item = array(
		"%title%"=>$destination_values[0]['name'].", ".display_sabs_date($values_top_deals['departure_date'],'jS F').", ".$values_top_deals['nights']."nts, from ".$item_departure_airport['simple']." ".$values_top_deals['price']." EURO",
		"%link%"=>$url_string, "%pubDate%"=>date('D, d M Y H:i:s',$values_top_deals['date'])
		);

  		$xml_items .= strtr($rss_item, $data_item);

  
	}
	
	$rss_complete = $rss_head.$xml_items.$rss_foot;
	
	
	}

	return $rss_complete;

}









}